﻿/*----------------------------------------------------------------
//  <copyright file="JsonWebToken.cs" company="MicroCloud@151504200868">
//      Copyright © 2020-2024 MicroCloud Corporation, All rights reserved.
//  </copyright>
//  <site>https://gitee.com/chenmm123/microclouds</site>
//  <last-editor>cmm</last-editor>
//  <last-date>2022-11-21 16:15</last-date>
//----------------------------------------------------------------*/

namespace MicroCloud.Identity.JwtBearer
{
    #region "JwtToken模型"
    /// <summary>
    /// JwtToken模型
    /// </summary>
    public class JsonWebToken
    {
        #region "属性"
        #region "获取或设置 用于业务身份认证的AccessToken"
        /// <summary>
        /// 获取或设置 用于业务身份认证的AccessToken
        /// </summary>
        public string AccessToken { get; set; }
        #endregion
        #region "获取或设置 AccessToken有效期，UTC标准"
        /// <summary>
        /// 获取或设置 AccessToken有效期，UTC标准
        /// </summary>
        public long AccessTokenExpiresUtc { get; set; }
        #endregion
        #region "获取或设置 用于刷新AccessToken的RefreshToken"
        /// <summary>
        /// 获取或设置 用于刷新AccessToken的RefreshToken
        /// </summary>
        public string RefreshToken { get; set; }
        #endregion
        #region "获取或设置 RefreshToken有效期，UTC标准"
        /// <summary>
        /// 获取或设置 RefreshToken有效期，UTC标准
        /// </summary>
        public long RefreshTokenExpiresUtc { get; set; }
        #endregion

        #endregion

        #region "方法"
        #region "AccessToken是否过期"
        /// <summary>
        /// AccessToken是否过期
        /// </summary>
        public bool IsAccessTokenExpired()
        {
            DateTime now = DateTime.Now;
            long nowTick = now.ToJsGetTime().CastTo<long>(0);
            return AccessTokenExpiresUtc > nowTick;
        }
        #endregion
        #region "RefreshToken是否过期"
        /// <summary>
        /// RefreshToken是否过期
        /// </summary>
        public bool IsRefreshTokenExpired()
        {
            DateTime now = DateTime.Now;
            long nowTick = now.ToJsGetTime().CastTo<long>(0);
            return RefreshTokenExpiresUtc > nowTick;
        }
        #endregion

        #endregion

    }
    #endregion

}
